<template>
  <div class="control-section">
    <div class="control-header">
      <span>弹窗</span>
      <span></span>
    </div>
    <div class="control-body">
      <div class="control-item">
        <div class="control-title flex-between">
          <span>弹出规则</span>
        </div>
        <div class="control-content">
          <a-select v-model="params.params.rule" class="fixed-top-select">
            <a-select-option :value="1"> 仅首次 </a-select-option>
            <a-select-option :value="2"> 每次 </a-select-option>
          </a-select>
        </div>
      </div>
      <uploadImg
        :imgList="params.params.list"
        @uploadSuccess="uploadSuccess"
        @deleteImg="deleteImg"
        type="list"
        @handleImgItem="choosePic"
        size="700*650px"
      ></uploadImg>
      <chooseLink
        :link="choosedPic.link"
        @chooseEnd="chooseLink"
        v-if="choosedPic.link"
        style="margin-top: 8px"
      ></chooseLink>
      <div class="switch-item">
        <span>是否展示</span>
        <a-switch v-model="params.is_show" />
      </div>
    </div>
  </div>
</template>

<script>
import uploadImg from '@/components/DiyNew/uploadImg/index.vue'
import chooseLink from '@/components/DiyNew/chooseLink/index.vue'
export default {
  name: 'widgetPopupControl',
  components: {
    uploadImg,
    chooseLink,
  },
  props: {
    params: {
      type: Object,
      default: {},
    },
  },
  data() {
    return {
      choosedPic: {},
    }
  },
  watch: {},
  computed: {},
  methods: {
    uploadSuccess(e) {
      console.log('上传成功回调', e)
      if (this.params.params.list.length >= 3) {
        return
      } else {
        // this.params.params.list.push({
        //   picUrl: e.val,
        //   link: {},
        // });
        // console.log(this.params.params.list);
        let arr = JSON.parse(JSON.stringify(this.params.params.list))
        arr.push({
          picUrl: e.val,
          link: {},
        })
        this.$setWithAction(this.params.params, 'list', arr)
      }
    },
    deleteImg(e) {
      console.log(e)
      // this.params.params.list.splice(e.index, 1);
      // this.choosedPic = {};
      let arr = JSON.parse(JSON.stringify(this.params.params.list))
      arr.splice(e.index, 1)
      this.$setWithAction(this.params.params, 'list', arr)
      this.choosedPic = {}
    },
    choosePic(e) {
      console.log(e)
      this.choosedPic = e.item
    },
    chooseLink(e) {
      // this.$set(this.choosedPic, "link", e);
      this.$setWithAction(this.choosedPic, 'link', e)
    },
  },
}
</script>

<style lang="scss" scoped>
.control-section {
  width: 100%;
  margin: 0 auto;
  text-align: center;
  .control-header {
    width: 100%;
    height: 48px;
    background: #ffffff;
    border-bottom: 1px solid #f0f2f5;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 24px;
    span:first-child {
      font-weight: 600;
      color: #000000;
    }
    span:last-child {
      font-size: 12px;
      color: #8c8c8c;
    }
  }
  .control-body {
    width: 228px;
    margin: 0 auto;
    .control-item {
      width: 100%;
      .control-title {
        padding: 24px 0 14px 0;
        text-align: left;
        font-size: 12px;
        color: #000000;
      }
      .control-content {
        width: 228px;
        height: 40px;
        background: #f6f7f9;
        border-radius: 4px;
        .ant-input {
          height: 100%;
          border: 0 none;
          background: #f6f7f9;
        }
      }
    }
    .switch-item {
      width: 228px;
      height: 40px;
      background: #f6f7f9;
      border-radius: 4px;
      margin-top: 24px;
      display: flex;
      align-items: center;
      justify-content: space-between;
      padding: 0 14px;
    }
  }
}
.control-item {
  width: 228px;
  margin: 0 auto;
  text-align: center;
}
.control-title {
  padding: 24px 0 14px 0;
  font-size: 12px;
  color: #000000;
  text-align: left;
}
.flex-between {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.reset {
  font-size: 12px;
  color: #9e9e9e;
  cursor: pointer;
}
.control-content {
  .example-list {
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    .example-item {
      width: 70px;
      height: 38px;
      background: #f6f7f9;
      border-radius: 4px;
      margin-right: 9px;
      display: flex;
      justify-content: center;
      align-items: center;
      cursor: pointer;
      img {
        width: 42px;
        height: 18px;
      }
    }
    .example-item:last-child {
      margin-right: 0;
    }
    .active {
      border: 2px solid #1890fc;
    }
  }
  .border-select,
  .fixed-top-select {
    width: 100%;
    height: 100%;
    ::v-deep .ant-select-selection--single {
      height: 100%;
      border: 0 none;
      background: #f2f2f2;
    }
    ::v-deep .ant-select-selection__rendered {
      line-height: 40px;
    }
  }
  .keyword-input {
    width: 228px;
    height: 40px;
    background: #f6f7f9;
    border-radius: 4px;
    input {
      height: 100%;
      background-color: #f6f7f9;
      border: 0 none;
    }
  }
}
.switch-item {
  width: 228px;
  height: 40px;
  background: #f6f7f9;
  border-radius: 4px;
  margin-top: 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
}
</style>
